package com.ssps.back.property.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssps.back.property.service.PropertyService;
import com.ssps.entity.GoodPercent;
import com.ssps.entity.Parking;
import com.ssps.entity.User;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("property")
public class PropertyController {
    @Autowired
    PropertyService propertyService;

    @RequestMapping("showParkList")
    @ResponseBody
    public Map<String, Object> showParkList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize", defaultValue = "5") Integer pageSize, String info, HttpSession session, String statuses) {
        Map<String, Object> map = new HashMap<>();
        try {
            PageHelper.startPage(pageNum, pageSize);
            User loginUser = (User) session.getAttribute("loginUser");
            List<Parking> list = propertyService.selectAll(info, loginUser, statuses);
            PageInfo<Parking> pageInfo = new PageInfo<Parking>(list);
            map.put("pageInfo", pageInfo);
            map.put("showParkingList", list);
            map.put("result", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("result", false);
        }
        return map;
    }

    @RequestMapping("ordersStatus")
    @ResponseBody
    public Map<String, Object> ordersStatus(Integer YEAR) {
        Map<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> map2 = propertyService.selectCountStatus(YEAR);
            map.put("ordersstatus", map2);
            map.put("result", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("result", false);
        }
        return map;
    }

    @RequestMapping("goodB")
    @ResponseBody
    public Map<String, Object> goodB(Integer YEAR) {
        Map<String, Object> map = new HashedMap();
        try {
            List<GoodPercent> list = propertyService.selecStatementPercent(YEAR);
            map.put("percent", list);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return map;
    }

    @RequestMapping("changeDATA")
    @ResponseBody
    public Map<String, Object> changeDATA() {
        Map<String, Object> map = new HashMap<>();
        try {
            Map<String, Integer> map2 = propertyService.selectAllOrders();
            Map<String, Integer> map3 = propertyService.selectAllParking();
            Map<String, Double> map4 = propertyService.selectMoney();
            Map<String, Integer> map5 = propertyService.selectAllComplain();
            map.put("complain", map5);
            map.put("money", map4);
            map.put("parking", map3);
            map.put("orders", map2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @RequestMapping("changeDATA2")
    @ResponseBody
    public Map<String, Object> changeDATA2() {
        Map<String, Object> map = new HashMap<>();
        try {
            Map<String, Object> map2 = propertyService.selectAllMoney();
            map.put("money", map2);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @RequestMapping("statement")
    public String statement() {
        return "propertyWeb/statement";
    }

    @RequestMapping("plantform_statement")
    public String plantform_statement() {
        return "propertyWeb/plantform_statement";
    }

    @RequestMapping("first")
    public String first() {
        return "propertyWeb/lease";
    }

}
